package org.travel.app.service.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.travel.app.entity.CouponDetail;
import org.travel.app.entity.Order;
import org.travel.app.entity.ticket.TicketOrderMsg;
import org.travel.app.mapper.OrderMapper;
import org.travel.app.mapper.ReservationMapper;
import org.travel.app.service.OrderService;

import java.util.List;

/**
 * @author nmm
 * @date 2024-12-2024/12/10
 * @deriction njm......
 */
@Service
@RequiredArgsConstructor
public class OrderServiceImpl implements OrderService {
private final OrderMapper orderMapper;
private final TicketServiceImpl ticketService;

    /**
     * 添加订单
     * @param order
     */
    @Override
    public Order saveOrder(Order order) {
           orderMapper.saveOrder(order);
           //生成订单
           if (order.getUserDiscountTicket()!=null){
               ticketService.userUsingTicket(order.getUserDiscountTicket());
               //用户使用优惠券消费
           }
           //用户
           return  order;
        //获取订单号用于查询订单及其门票相关信息
    }

    @Override
    public void addOrderCoupon(CouponDetail couponDetail) {
        orderMapper.addOrderCoupon(couponDetail);
    }

    /**
     * 查询所有订单
     * @return
     */
    @Override
    public List<Order> getOrderList(int orderId) {
       return orderMapper.getOrderList(orderId);
    }

    @Override
    public void updateOrderStatusByOrderId(Order order) {
            orderMapper.updateOrderStatusByOrderId(order);
    }

    @Override
    public TicketOrderMsg getOrderByOrderId(String orderId) {
        return orderMapper.getOrderByOrderId(orderId);
    }
}